import java.util.LinkedHashMap;
import java.util.Map;

public class LRUCacheOnLinkedHashMap extends LinkedHashMap<Integer, Integer> {
    public int capacity;

    public LRUCacheOnLinkedHashMap(int capacity){
        this.capacity = capacity;
    }

    @Override
    public Integer put(Integer key, Integer value) {
        return super.put(key, value);
    }

    @Override
    public Integer get(Object key) {
        return super.get(key);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<Integer, Integer> eldest) {
        return size() > capacity;
    }

    public static void main(String[] args) {
        LRUCacheOnLinkedHashMap lruCacheOnLinkedHashMap = new LRUCacheOnLinkedHashMap(3);

        lruCacheOnLinkedHashMap.put(1, 99);
        System.out.println(lruCacheOnLinkedHashMap);
        lruCacheOnLinkedHashMap.put(2, 89);
        System.out.println(lruCacheOnLinkedHashMap);
        lruCacheOnLinkedHashMap.put(3, 79);
        System.out.println(lruCacheOnLinkedHashMap);

        lruCacheOnLinkedHashMap.get(1);
        System.out.println(lruCacheOnLinkedHashMap);
        lruCacheOnLinkedHashMap.get(2);
        System.out.println(lruCacheOnLinkedHashMap);

        lruCacheOnLinkedHashMap.put(4, 66);
        System.out.println(lruCacheOnLinkedHashMap);

        lruCacheOnLinkedHashMap.put(5, 55);
        System.out.println(lruCacheOnLinkedHashMap);

        lruCacheOnLinkedHashMap.get(1);
        System.out.println(lruCacheOnLinkedHashMap);
    }
}
